﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ProjetoJornada_Negocios.Fachada;
using System.IO;
using System.Drawing;

namespace ProjetoJornada.Interno
{
    public partial class Imagem : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int idCurso = Convert.ToInt32(Request.QueryString["id"].ToString());

            byte[] logo = Fachada.Instance.ConsultarLogoCurso(idCurso);

            if (logo != null)
            {
                MemoryStream mstream = new MemoryStream(logo, 0, logo.Length);
                Image dbImage = Image.FromStream(new MemoryStream(logo));
                Image thumbnailImage = dbImage.GetThumbnailImage(100, 124, null, new IntPtr());

                thumbnailImage.Save(mstream, dbImage.RawFormat);
                Byte[] thumbnailByteArray = new Byte[mstream.Length];
                mstream.Position = 0;
                mstream.Read(thumbnailByteArray, 0, Convert.ToInt32(mstream.Length));
                Response.BinaryWrite(thumbnailByteArray);
            }
            else
            {
                Response.TransmitFile("../imagens/noimage.png");
            }
        }
    }
}
